package data

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/core"
	"github.com/go-xorm/xorm"

	"MyNotesWeb/bean"
)

var engine *xorm.Engine

func GetEngine() (*xorm.Engine, error) {
	engine, err := xorm.NewEngine("mysql", "tc:tc123456@tcp(127.0.0.1:3306)/my_notes?charset=utf8")
	if err == nil {
		tbMapper := core.NewPrefixMapper(core.SnakeMapper{}, "t_")
		engine.SetTableMapper(tbMapper)

		err = engine.Sync2(new(bean.Article), new(bean.User))
	}

	return engine, err
}
